import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mahjong/const/MahjongSystemConst.dart';
import 'package:mahjong/widget/MahjongCommon.dart';

class RoomMessage extends AnimatedWidget {
  final String tips;
  final AnimationController controller;
  final String userName;
  final String headImage;
  const RoomMessage({
    Key key,
    this.tips: "位置提示",
    this.controller,
    this.userName,
    this.headImage,
  }) : super(key: key, listenable: controller);
  Animation<double> get _progress => listenable;
  @override
  Widget build(BuildContext context) {
    bool hasSafeArea =
        ScreenUtil().statusBarHeight > 0 || ScreenUtil().bottomBarHeight > 0;

    double headWidth = MahjongSystemConst.mahjongTopBarHeight / 3 * 2;
    return Align(
      alignment: Alignment(-1, -1),
      child: Opacity(
        opacity: _progress.value,
        child: SafeArea(
          child: Container(
            margin: EdgeInsets.only(top: 30.h, left: hasSafeArea ? 0.0 : 20.h),
            padding: EdgeInsets.symmetric(horizontal: 10.h, vertical: 5.h),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(5.h)),
            height: MahjongSystemConst.mahjongTopBarHeight,
            child: Material(
              color: Colors.transparent,
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Stack(
                    children: [
                      MahjongCommon.headerImage(headImage,
                          width: headWidth, height: headWidth),
                      userName != null
                          ? Align(
                              alignment: Alignment.bottomCenter,
                              child: Container(
                                width: headWidth,
                                height: 10.h,
                                alignment: Alignment.center,
                                color: Colors.white.withOpacity(0.3),
                                child: Text(
                                  userName,
                                  textAlign: TextAlign.center,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                      color: Colors.black, fontSize: 8.sp),
                                ),
                              ),
                            )
                          : SizedBox(),
                    ],
                  ),
                  SizedBox(
                    width: 10.h,
                  ),
                  Text(
                    tips,
                    style: TextStyle(color: Colors.black, fontSize: 12.sp),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
